package c16多线程;

public class 共享Runable示例 {

	public static void main(String[] args) {
		RunThread rt = new RunThread();
		new Thread(rt).start();
		new Thread(rt).start();
	}

}

class RunThread implements Runnable {

	private int i = 100;
	private boolean run = true;

	@Override
	public void run() {
		while (run) {
			synchronized (this) {
				if (i > 0) {
					try {
						Thread.sleep(5);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.err.println(Thread.currentThread().getName() + "--" + i--);
				} else {
					run = false;
				}
			}
		}
	}

}